var state = 1;
let url = "http://127.0.0.1:8000/";

$(function () {
    //登录的点击
    $("#user").click(function () {
        if (state === 1) {
            state = 0;

        } else {
            state = 1;

        }
    });
    $(document).keydown(function (e) {
        if (e.keyCode === 13) {
            login();
        }
    });
    $(".login-btn").click(function () {
        login()
    })
});


//登录的函数
function login(){
	let username;
	let password;
	if($(".account").val().trim()!=''){
		username = $(".account").val();
	}else{
		alert("账号不能为空！")
		return 0;
	}
	if($(".password").val().trim()!=''){
		password = $(".password").val();
	}else{
		alert("密码不能为空！")
		return 0;
	}	
		
		$.ajax({
			type: 'POST',
			url: "http://test.cn/user/login",
			dataType: "json",
			   headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
			data:{
				account: username,
				password: password,
				status: state
			},
			success: function(data) {
				if(data.code == 200) {
					  window.open("http://test.cn","_self")
				} else {
					 alert('账号密码错误！');
				}
			}
		});
             
}
